#  Copyright (c) 2020 - ~, WANGXI
#  
#  WIRELESS UDP AWK FILE
#  Used in NS-2 simulator
#  Clone from https://gitee.com/WangXi_Chn/ns2_modulelib
#  Note in https://www.yuque.com/wangxi_chn/kozrfl
#  
#  Change Logs:
#  Date           Author       Notes			Mail
#  2020-11-24     WangXi   	   first version	WangXi_Chn@foxmail.com

# count the UDP packet has been send and receive

BEGIN {
    largest_seq = 0;
    packet_send++;
}

{
    if($1 == "s" && $7 == "cbr"){
        if($6 > largest_seq){
            largest_seq = $6;
        }
    }

    if($1=="s"&&$3=="_0_"&&$4=="AGT"&&$7=="cbr"){
            packet_send++;
            send_time[$6] = $2;
    }

    if($1=="r"&&$3=="_1_"&&$4=="MAC"&&$7=="cbr"){
            packet_rcvd++;
            rcvd_time[$6] = $2;
    }
}

END {
    #printf("packet_send %d,packet_rcvd %d\n",packet_send,packet_rcvd);
    for(i = 0;i<largest_seq;i++){
        if(send_time[i]!=0&&rcvd_time[i]!=0){
            #printf("%d %f %f\n",i,send_time[i],rcvd_time[i]);
            #printf("%f %d\n",rcvd_time[i],i);
            printf("%f %d\n",send_time[i],i);
        }
    }
}


#/************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
